import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ToolTipItem } from "../../../../../com/mui/manager/ToolTipItem";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TilePanel } from "../../equipment/TilePanel";
import { PetExploreCardCellRenderer } from "./PetExploreCardCellRenderer";
import { ListEvent } from "../../../../../fl/events/ListEvent";
import { SPetExploreCard } from "../../../../../Message/Public/SPetExploreCard";
import { TweenMax } from "../../../../../com/greensock/TweenMax";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
//class PetExploreCardsPanel
    
    export  class PetExploreCardsPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._datap = new DataProvider();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._cardsMask = new Object /* flash.display.Sprite */();
            this._cardsMask.graphics.beginFill(16711680, 0.5);
            this._cardsMask.graphics.drawRect(-220, 0, 250, 120);
            this._cardsMask.graphics.endFill();
            this._cardsMask.mouseEnabled = false;
            this.addChild(this._cardsMask);
            this._showSprite = new Object /* flash.display.Sprite */();
            this._showSprite.mask = this._cardsMask;
            this.addChild(this._showSprite);
            this._selectSprite = new ToolTipItem();
            this._selectSprite.buttonMode = true;
            this._selectSprite.useHandCursor = true;
            this._selectSprite.x = 5;
            this._selectSprite.addEventListener(flash.events.MouseEvent.CLICK, this.onSelectClickHandler);
            this._showSprite.addChild(this._selectSprite);
            ObjCreate.createBitmap(ImagesConst.PetExploreCard, 0, 0, this._selectSprite);
            this._showBtn = GlobalClass.getInstance("showBtn");
            this._showBtn.scaleX = -1;
            this._showBtn.x = 13;
            this._showBtn.y = 10;
            this._selectSprite.addChild(this._showBtn);
            this._selectSprite.toolTipData = Language.getString(54545);
            ObjCreate.createBg(28, 0, 220, 120, this._showSprite, ImagesConst.ToolTipBg);
            ObjCreate.createBg(30, 2, 150, 28, this._showSprite, ImagesConst.TileBg);
            this._tipTxt = ObjCreate.createTextField(Language.getString(54546), 35, 10, 220, 20, this._showSprite, GlobalStyle.textFormat6);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            var loc1=0;
            while (loc1 < 10) 
            {
                ObjCreate.createBg(33 + loc1 % 5 * 43, 33 + Math.floor(loc1 / 5) * 43, 38, 38, this._showSprite, ImagesConst.PackItemBg);
                ++loc1;
            }
            this._itemsList = new TilePanel();
            this._itemsList.verticalGap = 0;
            this._itemsList.horizontalGap = 0;
            this._itemsList.columnWidth = 43;
            this._itemsList.rowHeight = 43;
            this._itemsList.setSize(230, 80);
            this._itemsList.setStyle("cellRenderer", PetExploreCardCellRenderer);
            this._itemsList.move(35, 35);
            this._itemsList.addEventListener(ListEvent.ITEM_CLICK, this.onItemClickHandler);
            this._showSprite.addChild(this._itemsList);
            return;
        }

        public updateCards(arg1: Array<any>, arg2: Boolean=false): void
        {
            var loc1=null;
            this._datap.removeAll();
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                loc1 = arg1[loc2] as SPetExploreCard;
                this._datap.addItem({"card": loc1, "isShowMenu": arg2});
                ++loc2;
            }
            this._itemsList.dataProvider = this._datap;
            return;
        }

        public showPanel(arg1: Boolean): void
        {
            var loc2=0;
            var loc1=this._showSprite.x;
            if (arg1) 
            {
                loc2 = -220;
                this._showBtn.scaleX = 1;
            }
            else 
            {
                loc2 = 0;
                this._showBtn.scaleX = -1;
            }
            TweenMax.to(this._showSprite, 1, {"x": loc2});
            return;
        }

        /* internal  */onSelectClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._showSprite.x;
            if (loc1 >= 0) 
            {
                this.showPanel(true);
            }
            else 
            {
                this.showPanel(false);
            }
            return;
        }

        /* internal  */onItemClickHandler(arg1: ListEvent): void
        {
            var loc1=arg1.item["card"] as SPetExploreCard;
            if (loc1) 
            {
                if (Cache.instance.petExplore.petExploreInfo.isInExplore) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreUseCard, {"uid": loc1.uid, "isDestroy": false}));
                }
            }
            return;
        }

        public set tip(arg1: string)
        {
            this._tip = arg1;
            this._tipTxt.htmlText = arg1;
            return;
        }

        /* internal */ /* var */_selectSprite: ToolTipItem;

        /* internal */ /* var */_showSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_showBtn: Object /* flash.display.SimpleButton */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemsList: TilePanel;

        /* internal */ /* var */_cardsMask: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tip: string;

        /* internal */ /* var */_datap: DataProvider;
    }
